package com.jy.event.domain;

import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;

/**
 * Created by hanxi on 2017/8/4.
 */
@Entity
@Data
@NoArgsConstructor
public class MemberAccount {
    @Id
    @Column(length = 50)
    private String id;
    private String storeId;
    /**
     * 推荐人id
     */
    private String referralUserId;
    /**
     * 推荐人名称
     */
    private String referralUserName;
    /**
     * 用户充值金额。会员消费时，默认先从该值扣减。如果余额不足，再从赠送金额扣减。不过赠送金额扣减时，要检查商品是否允许使用赠送金额
     */
    private double amount = 0;
    /**
     * 商户赠送金额
     */
    private double bonus = 0;
    private long points = 0;
    private boolean enabled = true;
    @Column(insertable = false, updatable = false, columnDefinition = "TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3)")
    private Date addTime;
    @Column(insertable = false, updatable = false, columnDefinition = "TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)")
    private Date updateTime;

    public double getTotalAmount() {
        return Math.rint((amount + bonus) * 100) / 100d;
    }
}
